// API related functions
export const sendPOSTRequest = () => {
    const xhr = new XMLHttpRequest();
    const url = "";
    const data = "username=" + encodeURIComponent(document.getElementById("usr").value) +
                "&password=" + encodeURIComponent(document.getElementById("pwd").value);
    console.log("Request data: ", data);
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send(data);
};

export const get_info = () => {
    const v = document.getElementsByName("data");
    const xhr = new XMLHttpRequest();
    const url = "";
    xhr.open("POST", url, true);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            console.log(xhr.responseText);
            const val = xhr.responseText.split(" ");
            for (let i = 0; i < v.length && i < val.length; i++) {
                v[i].value = val[i];
            }
        }
    };
    xhr.send("get");
};